Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

paho-mqtt

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paho-mqtt

Eclipse Paho JavaScript MQTT client for Browsers

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
120K
decreased by-34.32%
Maintainers
1
Weekly downloads
 
Created

What is paho-mqtt?

The paho-mqtt npm package is a client library for the MQTT protocol, which is a lightweight messaging protocol for small sensors and mobile devices optimized for high-latency or unreliable networks. The library allows you to connect to an MQTT broker, publish messages to topics, and subscribe to topics to receive messages.

What are paho-mqtt's main functionalities?

Connecting to an MQTT Broker

This feature allows you to connect to an MQTT broker. The code sample demonstrates how to create a client and connect to a broker using WebSockets.

const mqtt = require('paho-mqtt');
const client = new mqtt.Client('ws://broker.hivemq.com:8000/mqtt', 'clientId');
client.connect({
  onSuccess: () => {
    console.log('Connected to broker');
  }
});

Publishing Messages

This feature allows you to publish messages to a specific topic. The code sample shows how to send a message to the 'test/topic' topic after successfully connecting to the broker.

client.onConnectionLost = (responseObject) => {
  if (responseObject.errorCode !== 0) {
    console.log('Connection lost:', responseObject.errorMessage);
  }
};
client.onMessageArrived = (message) => {
  console.log('Message arrived:', message.payloadString);
};
client.connect({
  onSuccess: () => {
    const message = new mqtt.Message('Hello MQTT');
    message.destinationName = 'test/topic';
    client.send(message);
    console.log('Message sent');
  }
});

Subscribing to Topics

This feature allows you to subscribe to a specific topic to receive messages. The code sample demonstrates how to subscribe to the 'test/topic' topic and handle incoming messages.

client.onConnectionLost = (responseObject) => {
  if (responseObject.errorCode !== 0) {
    console.log('Connection lost:', responseObject.errorMessage);
  }
};
client.onMessageArrived = (message) => {
  console.log('Message arrived:', message.payloadString);
};
client.connect({
  onSuccess: () => {
    client.subscribe('test/topic');
    console.log('Subscribed to topic');
  }
});

Other packages similar to paho-mqtt

Keywords

FAQs

Package last updated on 22 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc